﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................
namespace QLKTX1._0.DAO
{
    class LoaiPhongDAO
    {
        public static List<LoaiPhongDTO> dsLoaiPhong()
        {
            List<LoaiPhongDTO> dsLoaiPhong = new List<LoaiPhongDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM loaiPhong");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LoaiPhongDTO loaiPhong = new LoaiPhongDTO();

                loaiPhong.MaLoaiPhong = dt.Rows[i]["maLoaiPhong"].ToString();
                loaiPhong.TenLoaiPhong = dt.Rows[i]["tenLoaiPhong"].ToString();

                dsLoaiPhong.Add(loaiPhong);

            }
            return dsLoaiPhong;
        }
        //Ham Insert
        public static bool themLoaiPhong(LoaiPhongDTO loaiPhong)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO loaiPhong(maLoaiPhong,tenLoaiPhong) VALUES('" + loaiPhong.MaLoaiPhong + "',N'" + loaiPhong.TenLoaiPhong + "')");

        }
        //Ham Delete
        public static bool xoaLoaiPhong(LoaiPhongDTO loaiPhong)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM loaiPhong WHERE maLoaiPhong='" + loaiPhong.MaLoaiPhong + "'");
        }
        //Ham Update
        public static bool capNhatLoaiPhong(LoaiPhongDTO loaiPhong)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE loaiPhong set tenLoaiPhong=N'" + loaiPhong.TenLoaiPhong + "' WHERE maLoaiPhong='" + loaiPhong.MaLoaiPhong + "'");
        }
    }
}
